package cn.edu.ctbu.lddweb.service.lmpl;

import cn.edu.ctbu.lddweb.mapper.SemesterMapper;
import cn.edu.ctbu.lddweb.pojo.Semester;
import cn.edu.ctbu.lddweb.service.SemesterService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 学期管理实现层
 */
@Service
public class SemesterServicelmpl implements SemesterService {

    @Autowired
    private SemesterMapper semesterMapper;

    @Override
    public List<Semester> selectList(Semester semester) {
        return semesterMapper.selectList(semester);
    }

    /**
     * 检查是否唯一
     * @param semester
     * @return
     */
    @Override
    public Boolean checkSemesterUnique(Semester semester) {
        int id = semester.getId()==0?-1:semester.getId();
        Semester info = semesterMapper.checkSemesterUnique(semester);
        if(info!=null&&info.getId()!=id){
            return true;
        }
        return false;
    }

    @Override
    public Semester findID(@Param("id") int id) {
        return semesterMapper.findID(id);
    }

    @Override
    public int insertSemester(Semester semester) {
        return semesterMapper.insertSemester(semester);
    }

    @Override
    public int updateSemester(Semester semester) {
        return semesterMapper.updateSemester(semester);
    }

    @Override
    public int deleteSemester(String id) {
        return semesterMapper.deleteSemester(id);
    }
}
